print("-------------两城温差比较-------------");
aStr = input("输入A城温度数据(数据格式：温度,截止时间;)：\n");
aList = aStr.split(";");
bStr = input("输入B城温度数据(数据格式：温度,持续时长;)：\n");
bList = bStr.split(";");

# 获取A城的温度列表和截止时间列表
temperature1 = []
time1 = []
for i in range(len(aList)):
    tmp = aList[i].split(",")
    temperature1.append(int(tmp[0]))
    time1.append(int(tmp[1]))
# 获取B城的温度列表和截止时间列表
temperature2 = []
time2 = []
for i in range(len(bList)):
    tmp = bList[i].split(",")
    temperature2.append(int(tmp[0]))
    time2.append(int(tmp[1]))
# 将A城第i个记录中的截止时间转换为持续时长
real = time1[:1]
for i in range(1, len(time1)):
    real.append(time1[i] - time1[i - 1])

# 持续时长最大为1小时，拆分温度数据
result1 = []
result2 = []
for i in range(len(real)):
    for j in range(real[i]):
        result1.append(temperature1[i])
for i in range(len(time2)):
    for j in range(time2[i]):
        result2.append(temperature2[i])
# 计算每个时段的温度差，得到列表
diff = []
for i in range(len(result1)):
    diff.append(result1[i] - result2[i])
# 计获取计算结果
put = []
count = 1
item = diff[0]
for i in range(1, len(diff)):
    if (diff[i] == diff[i - 1]):
        count = count + 1
    else:
        put.append(str(item) + "," + str(count))
        count = 1
        item = diff[i]
    if (i == len(diff) - 1):
        put.append(str(item) + "," + str(count))
# 输出到表格
print('  温差    持续时长')
for i in range(len(put)):
    print('  ' + put[i].split(",")[0] + '       ' + put[i].split(",")[1])

